package control.recipe;

import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import model.recipe.RecipeDescVO;
import model.recipe.RecipeVO;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

public class RecipeContoller extends MultiActionController{
	
	
	public ModelAndView write(HttpServletRequest request, HttpServletResponse response, HttpSession session){
		
		RecipeVO vo=new RecipeVO();

		String path="";
		int order=0;
		
		//wirte1 page에서 넘어온값
		String r_title=request.getParameter("r_title");
		String r_img=request.getParameter("r_img");
		String r_comment=request.getParameter("r_comment");
		
		//write2 page에서 넘어온값
		String r_category=request.getParameter("r_category");
		String r_nara=request.getParameter("r_nara");
		
		//write3 page에서 넘어온값
		String r_main_ingre=request.getParameter("r_main_ingre");
		String r_mcnt=request.getParameter("r_mcnt");
		String r_sub_ingre=request.getParameter("r_sub_ingre");
		
		//write4 page에서 넘어온값
		String r_subject=request.getParameter("r_subject");
		String r_img_path=request.getParameter("r_img_path");
		String r_content=request.getParameter("r_content");
		
//write1 page로 최초 보내기
		if(r_title==null){
			path="write1.recipe";
//write1 page에서 넘어온값  1
		}else if(r_title!=null){
			vo.setR_img(r_img);
			vo.setR_comment(r_comment);
			vo.setR_title(r_title);
			session.setAttribute("recipe", vo);
			path="write2.recipe";
//write2 page에서 넘어온값 2
		}else if(r_category!=null){
			vo.setR_type(r_category+r_nara);
			session.setAttribute("recipe", vo);
			path="write3.recipe";
//write3 page에서 넘어온값 3
		}else if(r_main_ingre!=null){
			vo.setR_main_ingre(r_main_ingre);	
			vo.setR_mcnt(Integer.parseInt(r_mcnt));
			vo.setR_sub_ingre(r_sub_ingre);
			session.setAttribute("recipe", vo);
			path="write4.recipe";
//write4 page에서 넘어온값 4
		}else{
			RecipeDescVO rdvo=new RecipeDescVO();
			rdvo.setR_content(r_content);
			rdvo.setR_img_path(r_img_path);
			rdvo.setR_order(order+1);
			ArrayList rdList=new ArrayList();
			rdList.add(rdvo);
			session.setAttribute("recipeD", rdList);
			path="write4.recipe";
		}
		System.out.println(path);
		return new ModelAndView(path);
	}
	
	
/*	public ModelAndView write_submit(HttpServletRequest request,HttpServletResponse response,HttpSession session){
		if(session.getAttribute("recipe")!=null&&session.getAttribute("recipeD")!=null){
			
		}
		return new ModelAndView();
	}*/
}
